<?php

class Action_Community_PersonSuggest extends RL_Handler
{
	protected function init ()
	{
		$this->aa = $this->module->aa;
		$this->ctx->mm->setAclAssistant($this->aa);
		$this->rh->UseClass("RL_URLGenerator");
		require_once 'json/json.php';

		$this->community = $this->ctx->store->getObject($this->aa->acl_data['comity_oid']);
		$this->m_person = $this->ctx->mm->getModel('Person', 'm');
	} // end of method init

	var $rq_query = 'q';
	public function process ()
	{
		$query = $this->rh->GET[$this->rq_query];
		$community_oid = $this->community->id;
		$personList= $this->m_person->suggestPerson($community_oid, $query);
		$res = array();
		if ($personList) {
			foreach ($personList as $person) {
				$item = $person->data;
				$item['oid'] = $person->id;
				$res[] = $item;
			}
		}
		$this->rh->response->setContent( json_encode($res), array('mime_type' => 'application/json'));
	} // end of function execute
}
